﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TaiwuZD
{
    /// <summary>
    /// TaiwuMapCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class TaiwuMapCtrl : UserControl
    {
        public TaiwuMapCtrl()
        {
            InitializeComponent();
        }

        public static RoutedCommand RemoveBuildingCommand { get; set; } = new RoutedCommand();

        public static RoutedCommand BuildBuildingCommand { get; set; } = new RoutedCommand();


        private void RemoveBuilding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Global.Inst.DestroyBuilding(lvBuildings.SelectedIndex);
        }

        private void RemoveBuilding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            var si = lvBuildings.SelectedItem as TwBuilding;
            e.CanExecute = si != null && si.Id != 0;
        }

        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            lvToBuild.ItemsSource = GameAssets.TwBuildings.Values.Where(x => x.BuildingType == (sender as ListView).SelectedIndex);//TaiwuBuildings.Buildings.Where(x => x.BuildingType == (sender as ListView).SelectedIndex);
        }

        private void BuildBuilding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = lvBuildings.SelectedIndex != -1 && lvToBuild.SelectedIndex != -1;
        }

        private void BuildBuilding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Global.Inst.BuildBuilding(lvBuildings.SelectedIndex,(lvToBuild.SelectedItem as TwBuilding));
        }
    }
}
